package org.wj.problem;

public class Reverse {

	public static void main(String[] args) {
		//9646324351 2147483647
		reverse(-2147483648);
	}

	public static int reverse(int x) {
		long y = x;
		long result;
		if (y >= 0) {
			StringBuilder stringBuilder = new StringBuilder(Long.toString(y));
			StringBuilder reverse = stringBuilder.reverse();
			result = Long.parseLong(reverse.toString());
		} else {
			StringBuilder stringBuilder = new StringBuilder(Long.toString(-y) + "-");
			StringBuilder reverse = stringBuilder.reverse();
			result = Long.parseLong(reverse.toString());
		}
		if (result < Integer.MIN_VALUE || result > Integer.MAX_VALUE) {
			return 0;
		} else {
			return (int) result;
		}
	}


}
